package com.lz.football.module.guide.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import lz.controls.LButton;
	import lz.controls.LItem;

	/**
	 *队徽item 
	 * @author lake
	 * 
	 */	
	public class GuideTeamIconItem extends LItem implements IComponent
	{
		/**
		 * 队徽按钮
		 */		
		private var itemBtn :LButton ;
		
		public function GuideTeamIconItem()
		{
			super();
		}
		/**
		 *设置获取数据 
		 * @param value
		 * 
		 */		
		override public function set data(value:*):void
		{
			super.data = value;
			var iconUrl :String = String(data.iconurl[0]);
			var inconSkin :DisplayObject = Reflection.createInstance(iconUrl);
			if(inconSkin)
			{
				DisplayObjectUtil.removeAllChildren(_symbolSkin.container);
				var scxy :Number = 0;
				var showSize :Number = 100;
				scxy = ((showSize / inconSkin.width) <= (showSize / inconSkin.height))?(showSize / inconSkin.width):(showSize / inconSkin.height);
				inconSkin.scaleX = scxy;
				inconSkin.scaleY = scxy;
				inconSkin.x = (showSize - inconSkin.width)/2;
				inconSkin.y = (showSize - inconSkin.height)/2;
				_symbolSkin.container.addChild(inconSkin);
			}
		}
		override public function get data():*
		{
			return super.data;
		}
		/**
		 * 选择
		 * 
		 */		
		override public function select():void
		{
			itemBtn.enable = false;
			itemBtn.buttonMode = false;
			itemBtn.setStatus(LButton.SELECT);
		}
		/**
		 * 去选择
		 * 
		 */		
		override public function unSelect():void
		{
			itemBtn.enable = true;
			itemBtn.buttonMode = true;
			itemBtn.setStatus(LButton.UP);
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.football.guide.teamItemSkin");
			this.addChild(_symbolSkin);
			itemBtn = new LButton(_symbolSkin);
			itemBtn.enable = true;
			itemBtn.buttonMode = true;
			addEvtListener();
		}
		/**
		 * 
		 * 添加事件
		 */		
		public function addEvtListener():void
		{
			itemBtn.addEventListener(MouseEvent.CLICK,clickHandler);
		}
		/**
		 *选择 
		 * @param e
		 * 
		 */		
		private function clickHandler(e :MouseEvent):void
		{
			this.dispatchEvent(new Event("GuideTeamIconItem_select",true));
		}
		/**
		 * 
		 * 删除事件
		 */		
		public function removeEvtListener():void
		{
			itemBtn.removeEventListener(MouseEvent.CLICK,clickHandler);
		}
		/**
		 * 
		 * 销毁
		 */		
		public function destroyView():void
		{
			removeEvtListener();
		}
	}
}